using Godot;
using System;

public partial class Icon : Sprite2D
{
    public float MofifyRatio = 10;

    public float MaxSpeed = 5000;

    public float MinSpeed = 1;

    public override void _Process(double delta)
    {
        //return;
        var mousePos = Global.Instance.GlobalMousePosition;

        var deltaVector = mousePos - Position;
        var speed = deltaVector.Length() * MofifyRatio;

        var realSpeed = Math.Clamp(speed, MinSpeed, MaxSpeed);

        var directVector = deltaVector.Normalized();
        var newPos = Position + directVector * realSpeed * (float)delta;

        var viewportRect = GetViewportRect();

        var cameraInfo = Global.Instance.Camera.Position + Global.Instance.Camera.Offset;
        
        newPos.X = Math.Clamp(newPos.X, cameraInfo.X, viewportRect.Size.X+ cameraInfo.X);
        newPos.Y = Math.Clamp(newPos.Y, cameraInfo.Y, viewportRect.Size.Y+ cameraInfo.Y);

        Position = newPos;

        base._Process(delta);
    }
}

